package com.csun.dsms.controller;

import com.csun.dsms.comment.core.annotation.Authorization;
import com.csun.dsms.comment.core.utils.wrapper.WrapMapper;
import com.csun.dsms.comment.core.utils.wrapper.Wrapper;
import com.csun.dsms.model.huang.*;
import com.csun.dsms.service.HgMarketDataService;
import com.csun.dsms.service.HgPushCycleService;
import com.csun.dsms.service.HgReminderDataService;
import com.csun.dsms.utils.PublicUtil;
import com.csun.dsms.utils.pt.HuangGangUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 社零
 */
@RestController
@RequestMapping("/hgPushCycle")
public class HgPushCycleController {
    
    @Resource
    private HgPushCycleService hgPushCycleService;
    @Resource
    private HgReminderDataService hgReminderDataService;

    /*
    * 设备的添加
    * */
    @Authorization
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Wrapper dataAdd (@RequestBody HgPushCycleData hgPushCycleData){
        if(PublicUtil.isEmpty(hgPushCycleData.getUserName().trim())){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,"用户不能为空");
        }
        Integer save = hgPushCycleService.save(hgPushCycleData);
        if(save<1){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,Wrapper.ERROR_MESSAGE);
        }
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE);
    }

    /*
     * 数据查询
     * */
    @Authorization
    @RequestMapping(value = "/dataListQuery",method = RequestMethod.POST)
    public Wrapper dataListQuery (@RequestBody HgQueryDto hgPushCycleData){
        List<HgPushCycleData> query = hgPushCycleService.queryList(hgPushCycleData);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE,new PageInfo<>(query));
    }

    @Authorization
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Wrapper dataUpdate (@RequestBody HgPushCycleData hgPushCycleData){
        if(PublicUtil.isEmpty(hgPushCycleData.getUserName().trim())){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,"用户不能为空");
        }
        Integer save = hgPushCycleService.update(hgPushCycleData);
        if(save<1){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,Wrapper.ERROR_MESSAGE);
        }
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE);
    }

    @Authorization
    @PostMapping(value = "/deleteById/{id}")
    public Wrapper deleteById (@PathVariable Long id){
        Integer result = hgPushCycleService.deleteByKey(id);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE,result);
    }



    /*
     * 数据查询
     * */
    @Authorization
    @RequestMapping(value = "/reminderList",method = RequestMethod.POST)
    public Wrapper reminderList (@RequestBody HgQueryDto hgPushCycleData){
        List<HgReminderData> query = hgReminderDataService.queryDataList(hgPushCycleData);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE,new PageInfo<>(query));
    }

}
